Skip to content

Conversation

camelid
Copy link
Member

@camelid camelid commented Feb 23, 2021

All the tests passed, so it doesn't seem they need to be shared.
Plus they should be item/page-specific.

I'm not sure why they were shared before. I think the reason id_map
worked as a shared value before is that it is cleared before rendering
each item (in render_item). And then I'm guessing deref_id_map
worked because it's a hashmap keyed by DefId, so there was no overlap
(though I'm guessing we could have had issues in the future).

Note that id_map currently still has to be cleared because otherwise
child items would inherit the id_map of their parent. I'm hoping to
figure out a way to stop cloning Context, but until then we have to
reset id_map.

Builds on top of #82356 (otherwise we'd have merge conflicts), so this is
blocked on that PR.

...and remove `Rc`s for the moved fields.

The only shared one that I didn't move was `cache`; see the doc-comment
I added to `cache` for details.
It doesn't look like it's shared across threads, so it doesn't need to
be thread-safe. Of course, since we're using Rust, we'll get an error if
we try to share it across threads, so this should be safe :)
It's cloned a lot, so we don't want it to grow in size unexpectedly.
The size is architecture-dependent.
All the tests passed, so it doesn't seem they need to be shared.
Plus they should be item/page-specific.

I'm not sure why they were shared before. I think the reason `id_map`
worked as a shared value before is that it is cleared before rendering
each item (in `render_item`). And then I'm guessing `deref_id_map`
worked because it's a hashmap keyed by `DefId`, so there was no overlap
(though I'm guessing we could have had issues in the future).

Note that `id_map` currently still has to be cleared because otherwise
child items would inherit the `id_map` of their parent. I'm hoping to
figure out a way to stop cloning `Context`, but until then we have to
reset `id_map`.
@camelid camelid added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 23, 2021
@rust-highfive
Copy link
Contributor

r? @GuillaumeGomez

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 23, 2021
@camelid camelid added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Feb 23, 2021
@camelid
Copy link
Member Author

camelid commented Feb 23, 2021

Only the last commit is new (the others will disappear once #82356 is merged and I rebase).

Comment on lines 113 to 117
/// The map used to ensure all generated 'id=' attributes are unique.
id_map: RefCell<IdMap>,
/// Tracks section IDs for `Deref` targets so they match in both the main
/// body and the sidebar.
deref_id_map: RefCell<FxHashMap<DefId, String>>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to get rid of the RefCells here because the fields are used all over the place.

Comment on lines 133 to 138
rustc_data_structures::static_assert_size!(Context<'_>, 72);
rustc_data_structures::static_assert_size!(Context<'_>, 152);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big size increase! Should I box the fields to reduce the size?

@camelid
Copy link
Member Author

camelid commented Feb 23, 2021

Instead of using this new PR, should I just add this commit to #82356? It would reduce the churn of moving the fields back and forth.

@GuillaumeGomez
Copy link
Member

@camelid I think it's fine to put the commit in #82356.

@camelid
Copy link
Member Author

camelid commented Feb 26, 2021

Okay, will do.

@camelid camelid added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 26, 2021
@camelid
Copy link
Member Author

camelid commented Feb 28, 2021

Cherry-picked into #82356. Closing this PR now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants